VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsSendEMail"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Public Sub SendErrorEmail(strErrorMsg As String)

Dim cJMail As clsJMail
Dim strEMailBody As String
Dim i As Integer

    On Error GoTo SendErrorEmailFix

    If TimeToEmail Then
    
        Set cJMail = New clsJMail
        
        ' Email Body
        strEMailBody = "Please be advised . . " & vbCrLf & vbCrLf
        strEMailBody = strEMailBody & "The following error occurred in the KeyTax Interface (ReceiveXml):" & vbCrLf
        strEMailBody = strEMailBody & strErrorMsg
        
        'Get mail settings
        cJMail.EMailServer = "trend1.liberty.co.za"
        cJMail.MsgFrom = "KtInterface.Receive@liberty.co.za"
        cJMail.MSGFromName = "KeyTax Interface"
        cJMail.MSGSubject = "KeyTax Interface"
        cJMail.MSGBody = strEMailBody
        
'        'Get recipients
'        i = 1
'        While objReg.GetEMailAddress(i) <> ""
'            cJMail.AddRecipient objReg.GetEMailAddress(i), objReg.GetEMailAddress(i)
'            i = i + 1
'        Wend

        'for testing
        cJMail.AddRecipient "IOD.BJM0509@MEMO2.LIBERTY.CO.ZA", "IOD.BJM0509@MEMO2.LIBERTY.CO.ZA"

        'Send Mail
        If Not cJMail.SendMSG Then
            'send email to one of us if we're not already on the distr list
            cJMail.EMailServer = "trend1.liberty.co.za"
            cJMail.MsgFrom = "KtInterface.Receive@liberty.co.za"
            cJMail.MSGFromName = "KeyTax Interface"
            cJMail.MSGSubject = "KeyTax Interface Emailing Error"
            cJMail.MSGBody = "Error: SendErrorEmail failed. Trying to send error message: " & vbCrLf & strErrorMsg
            cJMail.AddRecipient "IOD.BJM0509@MEMO2.LIBERTY.CO.ZA", "IOD.BJM0509@MEMO2.LIBERTY.CO.ZA"
            cJMail.SendMSG

        Else
            objReg.LastEmailDttm = Now
            'MsgBox "Sent Mail"
        End If
        
        ' Cleanup
        Set cJMail = Nothing
    
    End If
 
    Exit Sub
    
SendErrorEmailFix:
    MsgBox "SendErrorEmail : " & Err.Number & " - " & Err.Description

End Sub
'Public Sub SendLogEmail()
'
''   This function sends the log file via email to everyone in
''   the distribution list after each run
'
'    Dim cJMail As clsJMail
'    Dim strEMailBody As String
'    Dim i As Integer
'    Dim strLogFileName As String
'
'    On Error GoTo SendLogEmailFix
'
'    'If TimeToEmail Then
'    'check that some files were processed
'    If lngIdxFileCount > 0 Then
'
'        Set cJMail = New clsJMail
'
'        strLogFileName = objReg.LogFilePath & strCurrentLogFileName
'        If Dir(strLogFileName) = "" Then
'            GoTo ErrorAlert
'        End If
'
'        ' Email Body
'        strEMailBody = "KeyTax Interface Log file: " & strLogFileName & vbCrLf
'        strEMailBody = strEMailBody & "for batch run on: " & objReg.LastRunDttm
'
'        'Get mail settings
'        cJMail.EMailServer = "mail.liberty.co.za"
'        cJMail.MsgFrom = "KtInterface.Receive@liberty.co.za"
'        cJMail.MSGFromName = "KeyTax Interface"
'        cJMail.MSGSubject = "KeyTax Interface Log"
'        cJMail.MSGBody = strEMailBody
'
''        'Get recipients
''        i = 1
''        While objReg.GetEMailAddress(i) <> ""
''            cJMail.AddRecipient objReg.GetEMailAddress(i), objReg.GetEMailAddress(i)
''            i = i + 1
''        Wend
'
'        'for testing
'        cJMail.AddRecipient "IOD.BJM0509@MEMO2.LIBERTY.CO.ZA", "IOD.BJM0509@MEMO2.LIBERTY.CO.ZA"
'
'        'Add the log file as an attachemnt
'        cJMail.AddAttachment strLogFileName
'
'        'Send Mail
'        If Not cJMail.SendMSG Then
'ErrorAlert:
'            'send email to one of us if we're not already on the distr list
'            cJMail.EMailServer = "mail.liberty.co.za"
'            cJMail.MsgFrom = "KtInterface.Receive@liberty.co.za"
'            cJMail.MSGFromName = "KeyTax Interface"
'            cJMail.MSGSubject = "KeyTax Interface Emailing Error"
'            cJMail.MSGBody = "Error: SendLogEmail failed. Trying to send log file: " & vbCrLf & strLogFileName
'            cJMail.AddRecipient "IOD.BJM0509@MEMO2.LIBERTY.CO.ZA", "IOD.BJM0509@MEMO2.LIBERTY.CO.ZA"
'            cJMail.SendMSG
'        End If
'
'        ' Cleanup
'        Set cJMail = Nothing
'
'    End If
'
'    Exit Sub
'
'SendLogEmailFix:
'    MsgBox "SendLogEmail : " & Err.Number & " - " & Err.Description
'End Sub
Private Function TimeToEmail() As Boolean
         
    If LeftPad(DatePart("h", Now), "0", 2) & LeftPad(DatePart("n", Now), "0", 2) >= objReg.GetDayStart(DatePart("w", Now)) _
    And LeftPad(DatePart("h", Now), "0", 2) & LeftPad(DatePart("n", Now), "0", 2) <= objReg.GetDayEnd(DatePart("w", Now)) Then
        If Abs(DateDiff("n", CDate(objReg.LastEmailDttm), CDate(Now))) >= 60 Then
            TimeToEmail = True
        Else
            TimeToEmail = False
        End If
    Else
        TimeToEmail = False
    End If
    
    TimeToEmail = True
    
End Function

